﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Print_PrintThongKeDoanVien : System.Web.UI.Page
{
  
    List<tblDoanVien> val = new List<tblDoanVien>();
    List<tblChuyenCongTacDoan> list_chuyen_di = new List<tblChuyenCongTacDoan>();
    List<tblChuyenCongTacDoan> list_chuyen_den = new List<tblChuyenCongTacDoan>();
    protected void Page_Load(object sender, EventArgs e)
    {
        list_chuyen_di = MemberShip_ASP.listchuyendi;
        list_chuyen_den = MemberShip_ASP.listchuyenden;
        val=MemberShip_ASP.listdoanvien;
        lblngaylapbaocao.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);
        lbldonvibaocao.Text = MemberShip_ASP.tendonvi;
        lblKhoangthoigian.Text = MemberShip_ASP.khoangthoigia;
        int num_of_day=MemberShip_ASP.number_of_day;
        inthongke(val, num_of_day, list_chuyen_di, list_chuyen_den);
        //phan xuat excel
        try
        {
            Response.Clear();
            Response.AddHeader("content-disposition", "attachment; filename=FileName.xls");
            Response.Charset = "";
            Response.ContentType = "application/vnd.xls";
            System.IO.StringWriter stringWrite = new System.IO.StringWriter();
            System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            grid_Detail.RenderControl(htmlWrite);
            Response.Write(stringWrite.ToString());
            Response.End();
            Response.Redirect("javascript:window.close()");
        }
        catch (Exception ex)
        {
            Response.Write("<script>alert('" + ex.Message + "')</script>");
        }
    }
    public void inthongke(List<tblDoanVien> val, int num, List<tblChuyenCongTacDoan> listchuyendi, List<tblChuyenCongTacDoan> listchuyenden)
    {

        lblngaylapbaocao.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);
        //phat trien moi
        Label3.Text = val.Where(r => r.PhatTrienMoi == true).Count().ToString();
        //moi chuyen den
        Label4.Text = listchuyenden.Count().ToString();
        // _db.tblChuyenCongTacDoans.Where(r => r.DonViChuyenDen.Trim() == val.First().TrucThuoc.Trim()).Count().ToString();
        //truong thanh
        Label6.Text = val.Where(r => r.TrangThai == 3).Count().ToString();
        //doan vien bi xoa ten
        Label7.Text = val.Where(r => r.TrangThaiXoa == true).Count().ToString();
        //doan vien chuyen di
        Label8.Text = listchuyendi.Count().ToString();
        //.Count().ToString();
        //doan vien bi khai tru
        Label9.Text = val.Where(r => r.TrangThai == 5).Count().ToString();
        //doan vien la nu
        Label11.Text = val.Where(r => r.Phai == false).Count().ToString();
        //doan vien LOC THEO NGHE NGHIEP
        Label12.Text = val.Where(r => r.NgheNghiep.Substring(0, 2) == "SV").Count().ToString();
        Label13.Text = val.Where(r => r.NgheNghiep.Substring(0, 2) == "HS").Count().ToString();
        Label14.Text = val.Where(r => r.NgheNghiep.Substring(0, 2) == "CB").Count().ToString();
        Label15.Text = val.Where(r => r.NgheNghiep.Substring(0, 2) == "NN").Count().ToString();
        Label16.Text = val.Where(r => r.NgheNghiep.Substring(0, 2) == "DN").Count().ToString();
        //tong so tang
        Label2.Text = (Convert.ToInt32(Label3.Text) + Convert.ToInt32(Label4.Text)).ToString();
        //tong so giam
        Label5.Text = (Convert.ToInt32(Label6.Text) + Convert.ToInt32(Label7.Text) + Convert.ToInt32(Label8.Text) + Convert.ToInt32(Label9.Text)).ToString();

        //tong do dau ky:num la tong so doan vien dau ky
        Label1.Text = num.ToString();
        //TONG SO DOAN VIEN HIEN TAI
        if ((Convert.ToInt32(Label2.Text) - Convert.ToInt32(Label5.Text)) <= 0)
        {
            Label10.Text = Label2.Text;
        }
        else
        {
            Label10.Text = (num + Convert.ToInt32(Label2.Text) - Convert.ToInt32(Label5.Text)).ToString();
        }


    }


}